<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui-flex.css" />
    <style>
    </style>
</head>
<style>
    .home:before {
        content: url(../image/home.png);
    }

    .refresh:before {
        content: url(../image/refresh.png);
    }

    .company:before {
        content: url(../image/company.png);
    }

    .pa-title {
        font-size: 17px;
        color: black;
        font-weight: bold;
    }

    .pa-title-content {
        font-size: 17px;
        color: black;
    }

    body {
        background-color: #D9D8DB;
    }

    .pa_injection_start_t {
        background-color: #254060;
        height: 444px;
        color: white;
        overflow: auto;
    }

    .checkboxClass {
        margin-top: 17px;
    }

    .checkboxClassName {
        font-size: 28px;
    }

    .pa_injection_start {
        margin-top: 2%;
        height: 65px;
        line-height: 65px;
        width: 70%;
        margin-left: 20%;
        text-align: center;
    }

    .pa_injection_start_tut {
        height: 58px;
        line-height: 58px;
        float: left;
        width: 150px;
        font-size: 28px;
        color: white;
        margin-left: 15px;
        text-align: center;
        background-color: #4B7902;
    }

    p {
        font-size: 17px;
        color: black;
        font-weight: bold;
        text-align: center;
    }
</style>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #D9D8DB">
        <div style="width: 10%;height: 60px;float: left;padding-top: 6px;">
            <a class="aui-pull-left aui-btn ">
                <span class="aui-iconfont company"></span>
            </a>
        </div>
        <div style="width: 10%;height: 60px;float: left;">
            <div style="text-align: left;">
                <span class="pa-title">富晟安创</span>
            </div>
        </div>
        <div style="width: 70%;height: 60px;float: left;">
            <div style="width:18%; float: left; text-align: left;">
                <span class="pa-title-content" id="locationName"></span>
            </div>
            <div style="width:18%; float: left; text-align: left;">
                <span class="pa-title-content" id="workCenterName"></span>
            </div>
            <div style="width:24%; float: left; text-align: left;">
                <span class="pa-title-content" id="workCellName"></span>
            </div>
            <div style="width:40%; float: left; text-align: left;">
                <span class="pa-title-content" id="nowDate"></span>
            </div>
        </div>
        <div style="width: 5%;height: 50px;float: left;">
        </div>
        <div style="width: 5%;height: 50px;float: left;">
            <a class="aui-pull-right aui-btn" onclick="closeWin()">
                <span class="aui-iconfont home"></span>
            </a>
        </div>
    </header>
    <div class="aui-content">
        <div class="aui-flex-col aui-flex-center" style="height: 30px;">
            <div class="aui-flex-item-12">
                <p>开工</p>
            </div>
        </div>
        <div class="aui-flex-col aui-flex-center">
            <div class="aui-flex-item-12 pa_injection_start_t">
                <div class="aui-flex-col">
                    <div class="aui-flex-item-12">
                        <div class="aui-flex-col pa_injection_start">
                            <input class='aui-checkbox checkboxClass' type='checkbox' name="checkbox" id="kbdj"
                                value="kbdj">
                            <div class='aui-checkbox-name checkboxClassName'>1：开班点检</div>
                        </div>
                    </div>

                    <div class="aui-flex-item-12">
                        <div class="aui-flex-col pa_injection_start">
                            <input class='aui-checkbox checkboxClass' type='checkbox' name="checkbox" id="hgjjl"
                                value="hgjjl" checked>
                            <div class='aui-checkbox-name checkboxClassName'>2：烘干机记录</div>
                        </div>
                    </div>

                    <div class="aui-flex-item-12">
                        <div class="aui-flex-col pa_injection_start">
                            <input class='aui-checkbox checkboxClass' type='checkbox' name="checkbox" id="qt"
                                value="qt">
                            <div class='aui-checkbox-name checkboxClassName'>3：齐套</div>
                        </div>
                    </div>

                    <div class="aui-flex-item-12">
                        <div class="aui-flex-col pa_injection_start">
                            <input class='aui-checkbox checkboxClass' type='checkbox' name="checkbox" id="tljl"
                                value="tljl">
                            <div class='aui-checkbox-name checkboxClassName'>4：投料记录</div>
                        </div>
                    </div>

                    <div class="aui-flex-item-12">
                        <div class="aui-flex-col pa_injection_start">
                            <div class="pa_injection_start_tut" onclick="save()">
                                提交
                            </div>
                            <div class="pa_injection_start_tut" style="background-color: #D9001B;margin-left: 50px;"
                                onclick="cancle()">
                                关闭
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">

    var equipUniqueId = "";

    //初始化
    apiready = function () {
        //获取设备唯一号
        equipUniqueId = localStorage.getItem('equipUniqueId');
        //产线工位信息
        document.getElementById("locationName").innerHTML = api.pageParam.locationName;
        document.getElementById("workCenterName").innerHTML = api.pageParam.workCenterName;
        document.getElementById("workCellName").innerHTML = api.pageParam.workCellName;
        document.getElementById("nowDate").innerHTML = getTimeCommon();
        //当前时间刷新
        window.setInterval("getTime()", 1000);

        //查询记录
        doSearch();
    }

    //时间刷新
    function getTime() {
        document.getElementById("nowDate").innerHTML = getTimeCommon();
    }

    //查询记录
    function doSearch() {
        var workCellCode = "";
        //是否按工位查询：0否，1是
        var cjFlag = api.pageParam.cjFlag;
        if ("1" == cjFlag) {
            workCellCode = api.pageParam.workCellCode;
        }
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getAssemblyStartCheckSearch";
        var data = {
            values: {
                workCenterCode: api.pageParam.workCenterCode,
                workCellCode: workCellCode,
                proddate: api.pageParam.proddate,
                shiftCode: api.pageParam.shiftCode,
                workOrderCode: api.pageParam.workOrderCode,
                un: un,
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';
        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //成功
                if (myobj.code == 0) {

                    if (myobj.kbdj) {
                        document.getElementById('kbdj').checked = true;
                    } else {
                        document.getElementById('kbdj').checked = false;
                    }

                    if (myobj.hgjjl) {
                        document.getElementById('hgjjl').checked = true;
                    } else {
                        document.getElementById('hgjjl').checked = false;
                    }

                    if (myobj.qt) {
                        document.getElementById('qt').checked = true;
                    } else {
                        document.getElementById('qt').checked = false;
                    }

                    if (myobj.tljl) {
                        document.getElementById('tljl').checked = true;
                    } else {
                        document.getElementById('tljl').checked = false;
                    }
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert("网络连接超时!")
            }
        });
    }

    //提交
    function save() {

        //开班点检
        var kbdj = document.getElementById('kbdj').checked;
        //烘干机记录
        var hgjjl = document.getElementById('hgjjl').checked;
        //齐套
        var qt = document.getElementById('qt').checked;
        //投料记录
        var tljl = document.getElementById('tljl').checked;

        var msg = "";
        if (!kbdj) {
            msg += "未开班点检,"
        }
        if (!hgjjl) {
            msg += "无烘干机记录,"
        }

        if (!qt) {
            msg += "齐套检查未通过,"
        }

        if (!tljl) {
            msg += "无投料记录,"
        }

        //校验未通过
        if (msg != "") {
            msg = msg + "是否开工？";;

            //弹框提示
            var dialogBox = api.require('dialogBox');
            dialogBox.alert({
                texts: {
                    title: '提示',
                    content: msg,
                    leftBtnTitle: '否',
                    rightBtnTitle: '是'
                },
                styles: {
                    bg: '#fff',
                    w: 300,
                    corner: 2,
                    title: {
                        marginT: 20,
                        // icon: 'widget://res/gou.png',
                        iconSize: 40,
                        titleSize: 14,
                        titleColor: '#000'
                    },
                    content: {
                        color: '#000',
                        size: 14
                    },
                    left: {
                        marginB: 7,
                        marginL: 20,
                        w: 130,
                        h: 35,
                        corner: 2,
                        bg: 'rgba(0,0,0,0)',
                        size: 12
                    },
                    right: {
                        marginB: 7,
                        marginL: 10,
                        w: 130,
                        h: 35,
                        corner: 2,
                        bg: 'rgba(0,0,0,0)',
                        size: 12
                    }
                }
            }, function (ret) {
                //否
                if (ret.eventType == 'left') {
                    var dialogBox = api.require('dialogBox');
                    dialogBox.close({
                        dialogName: 'alert'
                    });

                    //是
                } else {
                    var dialogBox = api.require('dialogBox');
                    dialogBox.close({
                        dialogName: 'alert'
                    });

                    //更新开工状态
                    updateWorkOrderState("开工");
                }
            });

            //检验通过
        } else {

            //更新开工状态
            updateWorkOrderState("开工");
        }
    }

    //更新状态
    function updateWorkOrderState(state) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getAssemblyUpdateWorkOrder";
        var data = {
            values: {
                workOrderCodeStr: api.pageParam.workOrderCode,
                workCenterCode: api.pageParam.workCenterCode,
                workCellCode: api.pageParam.workCellCode,
                state: state,
                un: un,
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //成功
                if (myobj.code == 0) {
                    api.toast({
                        msg: "保存成功",
                        duration: 3000
                    });

                    //查询工单信息
                    cancle();

                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert("网络连接超时!")
            }
        });
    }

    //取消按钮
    function cancle() {
        api.closeWin({});
        api.execScript({
            name: api.pageParam.name,
            script: 'refresh()'
        });
    }

    //返回按钮
    function closeWin() {
        api.closeToWin({ name: api.pageParam.rootName });
        api.execScript({
            name: api.pageParam.rootName,
            script: 'refresh()'
        });
    }
</script>

</html>